<?php

namespace App\Http\Controllers\Home;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;

class MyorderController extends CommonController
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
	 //个人中心，我的订单显示页面
    public function index()
    {
		//$order = \DB::table("order")->where("uid",session("homeuser")->id)->where("recycled",0)->get();
		//$order = \DB::table("order")->where("uid",session("homeuser")->id)->where("recycled",0)->first();
		$order = \DB::table("order")->where("uid",session("homeuser")->id)->where("recycled",0)->distinct()->lists('orderForm');
		
		$list = array();
		
		foreach ($order as $v) {
			
			$list[] = \DB::table("order")->where("orderForm",$v)->get();
			
		}
		$config = \DB::table("config")->get();
		return view("home.personal.myorder",["order"=>$order,"list"=>$list,"config"=>$config]);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
	//我的订单，删除（即放入回收站） 
    public function show($id)
    {
		\DB::table("order")->where("uid",session("homeuser")->id)->where("orderForm",$id)->update(["recycled"=>1]);
		//$order = \DB::table("order")->where("uid",session("homeuser")->id)->where("recycled",0)->get();
		//return view("home.personal.myorder",["order"=>$order]);
        return redirect("home/myorder");
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        return $id;
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
